package com;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:冒泡排序（非递归）
 * User: YJ
 * Date: 2024-4-03
 * Time: 15:57
 */
public class BubbleExeNonRecursion {
    public static void main(String[] args) {
        int[] arr = new int[] {2,5,9,7,3,0};
        Bubble(arr,arr.length - 1);
        System.out.println(Arrays.toString(arr));
    }
    private static void Bubble(int[] array,int j) {
        do {
            int x = 0;
            for (int i = 0; i < j; i++) {
                if (array[i] > array[i + 1]) {
                    int t = array[i];
                    array[i] = array[i + 1];
                    array[i + 1] = t;
                    x = i;
                }
            }
            j = x;
        }while (j != 0);
    }
}
